package com.hly.musicbackground.model.auth.rest;


import com.hly.musicbackground.domain.Version;
import com.hly.musicbackground.model.auth.VO.VersionVO;
import com.hly.musicbackground.model.auth.params.InspectParams;
import com.hly.musicbackground.model.auth.service.VersionService;
import com.hly.musicbackground.result.Code;
import com.hly.musicbackground.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 版本控制
 * */
@RestController
@RequestMapping("/api/version")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "版本控制")
public class VersionController {

    private final VersionService versionService;

    /**
     * 查询所有版本信息
     * */
    @GetMapping("/list")
    @ApiOperation(value = "查询所有版本信息")
    public Result getList(@RequestParam(defaultValue = "all") String type){
        return Result.ok(versionService
                .lambdaQuery().eq(!"all".equals(type), Version::getType, type)
                .orderByDesc(Version::getVersionKey)
                .list());
    }

    /**
     * 查询版本详情
     * */
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "查询版本详情")
    public Result getDetail(@PathVariable("id") int id){
        return Result.ok(versionService.getById(id));
    }

//    @GetMapping("/info")
//    public Result getInfo(){
//        Code.BUSINESS_ERR("");
//        return Result.ok();
//    }

    /**
     * 检查版本
     * */
    @GetMapping("/inspect")
    @ApiOperation(value = "检查版本")
    public Result<VersionVO> inspect(InspectParams params){
        return Result.ok(versionService.inspect(params));
    }
}
